﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using AMS.DataAccess.Trademark.BO;
using AMS.DataAccess.Trademark.Filters;
using AMS.DataAccess.Trademark.Interfaces;
using AMS.UI.Controls;
using App;
using AMS.UI.Forms;

namespace AMSTrademarkClient.Tasks
{
    public partial class FrmMyTasks : BaseForm, IWorkControl
    {
        public FrmMyTasks()
        {
            InitializeComponent();
            summaryBar1.ListView = lv;
            wmSearch = new WaterMarkerTextBoxDecorector(txtFilter.TextBox, "请输入关键字");
            txtFilter.TextBox.TextChanged += new EventHandler(txtFilterTextBox_TextChanged);
            DoDataBind();
        }


        WaterMarkerTextBoxDecorector wmSearch;

        void DoDataBind()
        {
            ITaskManager taskMgr = ManagerFactory.CreateTaskManager();
            TaskFilter filter = new TaskFilter();
            filter.OwnerID = Globals.CallContext.UserID;
            List<TaskInfo> tasks = taskMgr.GetTaskList(Globals.CallContext, filter);
            lv.AddObjects(tasks);
        }

        private void biEdit_Click(object sender, EventArgs e)
        {
            new FrmEditTask().ShowDialog();
        }


        void txtFilterTextBox_TextChanged(object sender, EventArgs e)
        {
            if (txtFilter.TextBox.Focused)
            {
                int count = lv.FilterList(txtFilter.TextBox.Text);
                if (count != -1)
                {
                    lblTotal.Text = string.Format("共计：{0}", count);
                }
            }
        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
        }

        public bool ConfirmClose()
        {
            MessageBox.Show("不能关闭");
            return false;
        }
    }
}
